#include "stdio.h"
#include "SDL/SDL.h"
int  main(int argc, char *argv[])
{
    SDL_Surface *screen=NULL; //This pointer will reference the backbuffer
    SDL_Surface *image; //This pointer will reference our bitmap sprite
    SDL_Surface *temp;//This pointer will temporarily reference our bitmap sprite
    SDL_Event event;
    SDL_Rect x,y,x1;
    char pause;
    SDL_Surface *image1;
 SDL_Surface *ennemie1 = NULL;
    int tempsPrecedent = 0, tempsActuel = 0;
    int done=1;
     SDL_WM_SetCaption("Gestion du temps en SDL", NULL);



//We must first initialize the SDL video component, and check for success
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }
//Set the video mode to fullscreen 640x480 with 16bit colour and double- buffering
    screen = SDL_SetVideoMode(798, 543, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        printf("Unable to set video mode: %s\n", SDL_GetError());
        return 1;
    }
//Load the bitmap into a temporary surface, and check for success
    temp = SDL_LoadBMP("img/image.bmp");
    image1 = SDL_LoadBMP("img/mario.bmp");
    ennemie1 = SDL_LoadBMP("img/ennemie.bmp");
    SDL_SetColorKey(ennemie1, SDL_SRCCOLORKEY, SDL_MapRGB(ennemie1->format, 0, 0, 255));
    if (temp == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
//Convert the surface to the appropriate display format
    image = SDL_DisplayFormat(temp);
//Release the temporary surface
    SDL_FreeSurface(temp);
    x.x=0;

    x.y=395;
    x.w=image1->w;
    x.h=image1->h;
    x1.x=480;

    x1.y=445;




    SDL_EnableKeyRepeat(10, 10);
    while(done)

    {


        SDL_BlitSurface(image, NULL, screen, NULL);
        SDL_BlitSurface(image1, NULL, screen, &x);
        SDL_BlitSurface(ennemie1, NULL, screen, &x1);
        SDL_Flip(screen);
        while (SDL_PollEvent(&event))
        {

            switch (event.type)
            {

            case SDL_QUIT:
                done = 0 ;
                break;

               tempsActuel = SDL_GetTicks();
        if (tempsActuel - tempsPrecedent > 30)
        {


            x1.x++;
           tempsPrecedent = tempsActuel;
        }


            case SDL_KEYDOWN :


                if (event.key.keysym.sym == SDLK_ESCAPE)
                    done=0;


                if (event.key.keysym.sym == SDLK_RIGHT)
                    x.x++;


                if (event.key.keysym.sym == SDLK_LEFT)
                    x.x--;
                  if (event.key.keysym.sym == SDLK_UP)

x.y--;


                    if (event.key.keysym.sym == SDLK_DOWN)
                    x.y++;
                    break;



}

    }

        }





    SDL_FreeSurface(ennemie1);
     return EXIT_SUCCESS;
    SDL_Quit();




}
